package com.seleniti.enpareja.android.model.integration.engine.service.impl.japtsy;

import org.ioc.commons.impl.android.integration.service.japtsy.CookieManagerProvider;
import org.ioc.commons.impl.android.integration.service.japtsy.JAPTSYAndroidServiceFactory;
import org.ioc.commons.impl.android.integration.service.japtsy.JAPTSYMapping;
import org.ioc.commons.impl.android.integration.service.japtsy.JAPTSYMapping.Service;
import org.ioc.commons.impl.android.integration.service.japtsy.JAPTSYServiceManager;
import org.ioc.commons.japtsy.server.model.biz.JAPTSYService_Impl;
import org.ioc.commons.japtsy.server.model.biz.JAPTSYService_JDOImpl;

import android.content.Context;

import com.seleniti.enpareja.controller.model.integration.service.CoupleService;
import com.seleniti.enpareja.controller.model.integration.service.EnParejaServiceFactory;
import com.seleniti.enpareja.controller.model.integration.service.EnParejaServiceManager;
import com.seleniti.enpareja.controller.model.integration.service.HomeTaskService;
import com.seleniti.enpareja.controller.model.integration.service.MealService;
import com.seleniti.enpareja.controller.model.integration.service.NotificationService;
import com.seleniti.enpareja.controller.model.integration.service.PendingShoppingService;
import com.seleniti.enpareja.controller.model.integration.service.SecurityManagementService;
import com.seleniti.enpareja.controller.model.integration.service.UserService;
import com.seleniti.enpareja.controller.model.integration.service.WorkShiftService;

@JAPTSYMapping(services = {
		@Service(service = CoupleService.class, serverSideClassname = "com.seleniti.enpareja.web.desktop.server.model.integration.service.impl.appengine.GAECoupleService"),
		@Service(service = UserService.class, serverSideClassname = "com.seleniti.enpareja.web.desktop.server.model.integration.service.impl.appengine.GAEUserService"),
		@Service(service = HomeTaskService.class, serverSideClassname = "com.seleniti.enpareja.web.desktop.server.model.integration.service.impl.appengine.GAEHomeTaskService"),
		@Service(service = MealService.class, serverSideClassname = "com.seleniti.enpareja.web.desktop.server.model.integration.service.impl.appengine.GAEMealService"),
		@Service(service = WorkShiftService.class, serverSideClassname = "com.seleniti.enpareja.web.desktop.server.model.integration.service.impl.appengine.GAEWorkShiftService"),
		@Service(service = SecurityManagementService.class, serverSideClassname = "com.seleniti.enpareja.web.desktop.server.model.integration.service.impl.appengine.GAESecurityManagementService"),
		@Service(service = PendingShoppingService.class, serverSideClassname = "com.seleniti.enpareja.web.desktop.server.model.integration.service.impl.appengine.GAEPendingShoppingService"),
		@Service(service = NotificationService.class, serverSideClassname = "com.seleniti.enpareja.web.desktop.server.model.integration.service.impl.appengine.GAENotificationService"), }, domainPackages = {
		"com.seleniti.enpareja.controller.common.domain",
		"com.seleniti.enpareja.controller.model.integration.database.domain" })
public class EnParejaServiceManagerImpl extends JAPTSYServiceManager<EnParejaServiceFactory> implements
		EnParejaServiceManager {

	protected final JAPTSYService_Impl serviceImpl = new JAPTSYService_JDOImpl();

	private EnParejaServiceFactory serviceFactory;

	private String moduleBaseUrl;
	private String remoteServiceRelativePath;

	public EnParejaServiceManagerImpl(Context applicationContext, CookieManagerProvider cookieManagerProvider) {
		super(applicationContext, cookieManagerProvider);
	}

	@Override
	public EnParejaServiceFactory serviceFactory() {
		if (this.serviceFactory == null) {
			this.serviceFactory = JAPTSYAndroidServiceFactory.generate(this, EnParejaServiceFactory.class, serviceImpl,
					getServerSideClassnames(), moduleBaseUrl, remoteServiceRelativePath, queueRequests, true);
			
		}
		return this.serviceFactory;
	}

	public String getModuleBaseUrl() {
		return moduleBaseUrl;
	}

	public void setModuleBaseUrl(String moduleBaseUrl) {
		this.moduleBaseUrl = moduleBaseUrl;
		if (this.serviceFactory instanceof JAPTSYAndroidServiceFactory) {
			((JAPTSYAndroidServiceFactory) this.serviceFactory).setModuleBaseUrl(moduleBaseUrl);
		}
	}

	public String getRemoteServiceRelativePath() {
		return remoteServiceRelativePath;
	}

	public void setRemoteServiceRelativePath(String remoteServiceRelativePath) {
		this.remoteServiceRelativePath = remoteServiceRelativePath;
		if (this.serviceFactory instanceof JAPTSYAndroidServiceFactory) {
			((JAPTSYAndroidServiceFactory) this.serviceFactory).setRemoteServiceRelativePath(remoteServiceRelativePath);
		}
	}

}
